home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH8 / SRC / PICKOVER.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-12-30  |  10.4 KB  |  377 lines

  1. VERSION 4.00
  2. Begin VB.Form PickoverForm 
  3.    Caption         =   "Pickover"
  4.    ClientHeight    =   5430
  5.    ClientLeft      =   1800
  6.    ClientTop       =   990
  7.    ClientWidth     =   6375
  8.    Height          =   6120
  9.    Left            =   1740
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   362
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   425
  14.    Top             =   360
  15.    Width           =   6495
  16.    Begin VB.Frame Frame1 
  17.       Caption         =   "Projection"
  18.       Height          =   1095
  19.       Left            =   0
  20.       TabIndex        =   19
  21.       Top             =   3120
  22.       Width           =   930
  23.       Begin VB.OptionButton AxesChoice 
  24.          Caption         =   "YZ"
  25.          Height          =   255
  26.          Index           =   2
  27.          Left            =   120
  28.          TabIndex        =   22
  29.          Top             =   720
  30.          Width           =   615
  31.       End
  32.       Begin VB.OptionButton AxesChoice 
  33.          Caption         =   "XZ"
  34.          Height          =   255
  35.          Index           =   1
  36.          Left            =   120
  37.          TabIndex        =   21
  38.          Top             =   480
  39.          Width           =   615
  40.       End
  41.       Begin VB.OptionButton AxesChoice 
  42.          Caption         =   "XY"
  43.          Height          =   255
  44.          Index           =   0
  45.          Left            =   120
  46.          TabIndex        =   20
  47.          Top             =   240
  48.          Value           =   -1  'True
  49.          Width           =   615
  50.       End
  51.    End
  52.    Begin VB.TextBox Z0Text 
  53.       Height          =   285
  54.       Left            =   240
  55.       TabIndex        =   18
  56.       Text            =   "0"
  57.       Top             =   2640
  58.       Width           =   615
  59.    End
  60.    Begin VB.TextBox Y0Text 
  61.       Height          =   285
  62.       Left            =   240
  63.       TabIndex        =   16
  64.       Text            =   "0"
  65.       Top             =   2280
  66.       Width           =   615
  67.    End
  68.    Begin VB.TextBox X0Text 
  69.       Height          =   285
  70.       Left            =   240
  71.       TabIndex        =   14
  72.       Text            =   "0"
  73.       Top             =   1920
  74.       Width           =   615
  75.    End
  76.    Begin VB.TextBox EText 
  77.       Height          =   285
  78.       Left            =   240
  79.       TabIndex        =   12
  80.       Text            =   "1.0"
  81.       Top             =   1440
  82.       Width           =   615
  83.    End
  84.    Begin VB.TextBox DText 
  85.       Height          =   285
  86.       Left            =   240
  87.       TabIndex        =   10
  88.       Text            =   "-2.5"
  89.       Top             =   1080
  90.       Width           =   615
  91.    End
  92.    Begin VB.TextBox CText 
  93.       Height          =   285
  94.       Left            =   240
  95.       TabIndex        =   8
  96.       Text            =   "-0.6"
  97.       Top             =   720
  98.       Width           =   615
  99.    End
  100.    Begin VB.TextBox BText 
  101.       Height          =   285
  102.       Left            =   240
  103.       TabIndex        =   6
  104.       Text            =   "0.5"
  105.       Top             =   360
  106.       Width           =   615
  107.    End
  108.    Begin VB.TextBox AText 
  109.       Height          =   285
  110.       Left            =   240
  111.       TabIndex        =   4
  112.       Text            =   "2.0"
  113.       Top             =   0
  114.       Width           =   615
  115.    End
  116.    Begin VB.CommandButton CmdClear 
  117.       Caption         =   "Clear"
  118.       Default         =   -1  'True
  119.       Height          =   495
  120.       Left            =   120
  121.       TabIndex        =   2
  122.       Top             =   4920
  123.       Width           =   735
  124.    End
  125.    Begin VB.PictureBox Canvas 
  126.       AutoRedraw      =   -1  'True
  127.       BackColor       =   &H00000000&
  128.       FillStyle       =   0  'Solid
  129.       ForeColor       =   &H000000FF&
  130.       Height          =   5415
  131.       Left            =   960
  132.       ScaleHeight     =   357
  133.       ScaleMode       =   3  'Pixel
  134.       ScaleWidth      =   357
  135.       TabIndex        =   1
  136.       Top             =   0
  137.       Width           =   5415
  138.    End
  139.    Begin VB.CommandButton CmdGo 
  140.       Caption         =   "Go"
  141.       Height          =   495
  142.       Left            =   120
  143.       TabIndex        =   0
  144.       Top             =   4320
  145.       Width           =   735
  146.    End
  147.    Begin VB.Label Label1 
  148.       Caption         =   "Z0"
  149.       Height          =   255
  150.       Index           =   7
  151.       Left            =   0
  152.       TabIndex        =   17
  153.       Top             =   2640
  154.       Width           =   255
  155.    End
  156.    Begin VB.Label Label1 
  157.       Caption         =   "Y0"
  158.       Height          =   255
  159.       Index           =   6
  160.       Left            =   0
  161.       TabIndex        =   15
  162.       Top             =   2280
  163.       Width           =   255
  164.    End
  165.    Begin VB.Label Label1 
  166.       Caption         =   "X0"
  167.       Height          =   255
  168.       Index           =   5
  169.       Left            =   0
  170.       TabIndex        =   13
  171.       Top             =   1920
  172.       Width           =   255
  173.    End
  174.    Begin VB.Label Label1 
  175.       Caption         =   "E"
  176.       Height          =   255
  177.       Index           =   4
  178.       Left            =   0
  179.       TabIndex        =   11
  180.       Top             =   1440
  181.       Width           =   255
  182.    End
  183.    Begin VB.Label Label1 
  184.       Caption         =   "D"
  185.       Height          =   255
  186.       Index           =   3
  187.       Left            =   0
  188.       TabIndex        =   9
  189.       Top             =   1080
  190.       Width           =   255
  191.    End
  192.    Begin VB.Label Label1 
  193.       Caption         =   "C"
  194.       Height          =   255
  195.       Index           =   2
  196.       Left            =   0
  197.       TabIndex        =   7
  198.       Top             =   720
  199.       Width           =   255
  200.    End
  201.    Begin VB.Label Label1 
  202.       Caption         =   "B"
  203.       Height          =   255
  204.       Index           =   1
  205.       Left            =   0
  206.       TabIndex        =   5
  207.       Top             =   360
  208.       Width           =   255
  209.    End
  210.    Begin VB.Label Label1 
  211.       Caption         =   "A"
  212.       Height          =   255
  213.       Index           =   0
  214.       Left            =   0
  215.       TabIndex        =   3
  216.       Top             =   0
  217.       Width           =   255
  218.    End
  219.    Begin VB.Menu mnuFile 
  220.       Caption         =   "&File"
  221.       Begin VB.Menu mnuFileExit 
  222.          Caption         =   "E&xit"
  223.       End
  224.    End
  225. Attribute VB_Name = "PickoverForm"
  226. Attribute VB_Creatable = False
  227. Attribute VB_Exposed = False
  228. Option Explicit
  229. Const AXES_XY = 0
  230. Const AXES_XZ = 1
  231. Const AXES_YZ = 2
  232. Dim Running As Boolean
  233. Dim Axes As Integer
  234. Dim A As Single
  235. Dim B As Single
  236. Dim C As Single
  237. Dim D As Single
  238. Dim E As Single
  239. Dim X0 As Single
  240. Dim Y0 As Single
  241. Dim Z0 As Single
  242. ' ************************************************
  243. ' Draw the curve.
  244. ' ************************************************
  245. Sub DrawCurve()
  246. Const XMIN = -2.1
  247. Const XMAX = 2.1
  248. Const YMIN = -2.1
  249. Const YMAX = 2.1
  250. Const ZMIN = -1.2
  251. Const ZMAX = 1.2
  252. Dim wid As Single
  253. Dim hgt As Single
  254. Dim xoff As Single
  255. Dim yoff As Single
  256. Dim zoff As Single
  257. Dim xscale As Single
  258. Dim yscale As Single
  259. Dim zscale As Single
  260. Dim x As Single
  261. Dim y As Single
  262. Dim z As Single
  263. Dim x2 As Single
  264. Dim y2 As Single
  265. Dim i As Integer
  266.     ' See how much room we have.
  267.     wid = Canvas.ScaleWidth
  268.     hgt = Canvas.ScaleHeight
  269.     Select Case Axes
  270.         Case AXES_XY
  271.             xoff = wid / 2
  272.             yoff = hgt / 2
  273.             xscale = wid / (XMAX - XMIN)
  274.             yscale = hgt / (YMAX - YMIN)
  275.         Case AXES_XZ
  276.             xoff = wid / 2
  277.             zoff = hgt / 2
  278.             xscale = wid / (XMAX - XMIN)
  279.             zscale = hgt / (ZMAX - ZMIN)
  280.         Case AXES_YZ
  281.             yoff = wid / 2
  282.             zoff = hgt / 2
  283.             yscale = wid / (YMAX - YMIN)
  284.             zscale = hgt / (ZMAX - ZMIN)
  285.     End Select
  286.     ' Get the drawing parameters.
  287.     GetParameters
  288.     ' Compute the values.
  289.     x = X0
  290.     y = Y0
  291.     z = Z0
  292.     i = 0
  293.     Do While Running
  294.         ' Move to the next point.
  295.         x2 = Sin(A * y) - z * Cos(B * x)
  296.         y2 = z * Sin(C * x) - Cos(D * y)
  297.         z = Sin(x)
  298.         x = x2
  299.         y = y2
  300.         
  301.         ' Plot the point.
  302.         Select Case Axes
  303.             Case AXES_XY
  304.                 Canvas.PSet (x * xscale + xoff, y * yscale + yoff), vbRed
  305.             Case AXES_XZ
  306.                 Canvas.PSet (x * xscale + xoff, z * zscale + zoff), vbRed
  307.             Case AXES_YZ
  308.                 Canvas.PSet (y * yscale + yoff, z * zscale + zoff), vbRed
  309.         End Select
  310.         
  311.         ' To make things faster, only DoEvents
  312.         ' every 100 times.
  313.         i = i + 1
  314.         If i > 100 Then
  315.             i = 0
  316.             DoEvents
  317.         End If
  318.     Loop
  319. End Sub
  320. ' ************************************************
  321. ' Get the curve parameters.
  322. ' ************************************************
  323. Sub GetParameters()
  324.     If Not IsNumeric(AText.Text) Then AText.Text = "2"
  325.     If Not IsNumeric(BText.Text) Then BText.Text = ".5"
  326.     If Not IsNumeric(CText.Text) Then CText.Text = "-.6"
  327.     If Not IsNumeric(DText.Text) Then DText.Text = "-2.5"
  328.     If Not IsNumeric(EText.Text) Then EText.Text = "1"
  329.     If Not IsNumeric(X0Text.Text) Then X0Text.Text = "0"
  330.     If Not IsNumeric(Y0Text.Text) Then Y0Text.Text = "0"
  331.     If Not IsNumeric(Z0Text.Text) Then Z0Text.Text = "0"
  332.     A = CSng(AText.Text)
  333.     B = CSng(BText.Text)
  334.     C = CSng(CText.Text)
  335.     D = CSng(DText.Text)
  336.     E = CSng(EText.Text)
  337.     X0 = CSng(X0Text.Text)
  338.     Y0 = CSng(Y0Text.Text)
  339.     Z0 = CSng(Z0Text.Text)
  340. End Sub
  341. ' ************************************************
  342. ' Select the axes for projection.
  343. ' ************************************************
  344. Private Sub AxesChoice_Click(Index As Integer)
  345.     Axes = Index
  346. End Sub
  347. ' ************************************************
  348. ' Erase the canvas.
  349. ' ************************************************
  350. Private Sub CmdClear_Click()
  351.     Canvas.Cls
  352. End Sub
  353. Private Sub CmdGo_Click()
  354. Dim i As Integer
  355.     If Running Then
  356.         Running = False
  357.         CmdGo.Enabled = False
  358.         CmdGo.Caption = "Stopped"
  359.     Else
  360.         Running = True
  361.         CmdGo.Caption = "Stop"
  362.         DrawCurve
  363.         CmdGo.Enabled = True
  364.         CmdGo.Caption = "Go"
  365.     End If
  366. End Sub
  367. Private Sub Form_Resize()
  368.     Canvas.Move Canvas.Left, 0, _
  369.         ScaleWidth - Canvas.Left, ScaleHeight - 1
  370. End Sub
  371. Private Sub Form_Unload(Cancel As Integer)
  372.     End
  373. End Sub
  374. Private Sub mnuFileExit_Click()
  375.     Unload Me
  376. End Sub
  377.